//Written by Richard Lewis aka Trixmoto (c) 2007

var ox = oy = ol = ot = dl = dt = tl = tt = 0;
var dragging = false;
var dragdiv = sizediv = null;

function startdrag(e) {
  dragging = true;
  if(window.event) {
    if(!e) {
      e = window.event;
    }
    ox = e.clientX;
    oy = e.clientY;    
    dragdiv = e.srcElement;
  }
  else {
    e.stopPropagation();
    ox = e.pageX;
    oy = e.pageY;    
    dragdiv = e.target;
  }
  while(dragdiv.id=="") {
    dragdiv = dragdiv.parentNode;
  }
  findobj(MyForm,dragdiv.id);  
  dt = parseInt(dragdiv.style.top);
  dl = parseInt(dragdiv.style.left);
  ot = MyProp.top;
  ol = MyProp.left;    
  dragdiv.style.cursor = 'move';
  var pnt = document.getElementById("pointer").style.display = "none";
  return false;
}

function dodrag(e) {
  if(dragging) {
    var ny = nx = 0;
    if(window.event) {
      if(!e) {
        e = window.event;
      }
      nx = e.clientX;
      ny = e.clientY;
    }
    else {
      e.stopPropagation();
      nx = e.pageX;
      ny = e.pageY;
    }  
    dragdiv.style.top = dt+(ny-oy);
    dragdiv.style.left = dl+(nx-ox);
  }
  return false;
}

function stopdrag(e) {
  dragging = false;
  dragdiv.style.cursor = 'auto';
  var ny = nx = 0;
  if(window.event) {
    if(!e) {
      e = window.event;
    }
    nx = e.clientX;
    ny = e.clientY;    
  }
  else {
    e.stopPropagation();
    nx = e.pageX;
    ny = e.pageY;    
  }    
  MyProp.top = ot+(ny-oy);
  MyProp.left = ol+(nx-ox);  
  return showview();
}

function startresizer(e) {
  dragging = true;
  document.body.onmousemove = doresizer;
  if(window.event) {
    if(!e) {
      e = window.event;
    }
    ox = e.clientX;
    oy = e.clientY;    
    dragdiv = e.srcElement;
  }
  else {
    e.stopPropagation();
    ox = e.pageX;
    oy = e.pageY;    
    dragdiv = e.target;
  }
  while(dragdiv.id=="") {
    dragdiv = dragdiv.parentNode;
  }
  dt = parseInt(dragdiv.style.top);
  dl = parseInt(dragdiv.style.left);
  dragdiv.style.cursor = 'move';
  sizediv = document.getElementById("code");
  tt = parseInt(sizediv.offsetHeight);
  tl = parseInt(sizediv.offsetWidth);
  return false;
}

function doresizer(e) {
  if(!dragging) {
    return false;
  }
  var ny = nx = 0;
  if(window.event) {
    if(!e) {
      e = window.event;
    }
    nx = e.clientX;
    ny = e.clientY;
  }
  else {
    e.stopPropagation();
    nx = e.pageX;
    ny = e.pageY;
  }  
  dragdiv.style.top = dt+(ny-oy);
  dragdiv.style.left = dl+(nx-ox);
  sizediv.style.height = tt+(ny-oy);
  sizediv.style.width = tl+((nx-ox)*2);
  return true;
}

function stopresizer(e) {
  if(!dragging) {
    return false;
  }
  dragging = false;
  dragdiv.style.cursor = 'auto';
  document.body.onmousemove = null;
  return snapsize();
}

function snapsize() {
  dragdiv = document.getElementById("resizer");
  sizediv = document.getElementById("code");
  var pos = findpos(sizediv);
  dragdiv.style.top = parseInt(pos[1])+parseInt(sizediv.offsetHeight);
  dragdiv.style.left = parseInt(pos[0])+parseInt(sizediv.offsetWidth);
  return true;
}